<!-- <template>
	<view class="center dirCloumn content">
		<web-view v-if="isIos"   :src="'file://' + path"></web-view>
		<web-view  v-else :src="path"></web-view>
	</view>
</template>

<script>
	import { mapState, mapMutations } from "vuex";
	export default {
		data() {
			return {
				path:"",
				title:"",
				isIos:false,
			}
		},
		onReady() {
			
		},
		onShow() {
			const systemInfo = uni.getSystemInfoSync()
			const platform = systemInfo.osName
			if(platform=='ios'){
				this.isIos=true
			}else{
				this.isIos=false
			}
		},
		onLoad(){
			
			const { path,title } = this.$Route.query
			if(!path){
				this.$Toast("數據錯誤")
				setTimeout(()=>{
					this.toPage("Main")
				},1200)
			}else{
				this.$nextTick(()=>{
					this.path=path
					this.title=title
				})
				
			}
			
		},
		methods: {
			...mapMutations(['changeUserIdent','changeUserName']),
			toPage(name,params={}){
				this.$navi({
				    route:{
				        name,
						params
				    },
				})
			}
		}
	}
</script>

<style lang="scss">
	.content{
		min-height: 100vh;
	}
	.share{
		position: relative;
		z-index: 2;
		padding: 10rpx 30rpx;
		border: 2rpx solid #e6e6e6;
		border-radius: 8rpx;
	}
</style> -->

<template>
  <div>
    <pdf
      v-for="i in numPages" 
      :key="i"
      :src="src"
      :page="i"
      style="display: inline-block; width: 100%"
    ></pdf>
  </div>
</template>

<script>
import pdf from 'vue-pdf'

export default {
  components: {
    pdf
  },
  data() {
    return {
      src: null, 
      numPages: undefined,
	  path:null,
	  title:"",
    }
  },
  mounted() {
	const { path,title } = this.$Route.query
	if(!path){
		this.$Toast("數據錯誤")
		setTimeout(()=>{
			this.toPage("Main")
		},1200)
	}else{
		this.$nextTick(()=>{
			this.path=path
			this.title=title
			this.$Loading();
			const loadingTask = pdf.createLoadingTask(path)
			loadingTask.promise.then(pdf => {
			  this.src = loadingTask 
			  this.numPages = pdf.numPages
			  setTimeout(()=>{
				uni.hideLoading()
			  },500)
			}).catch((err)=>{
				uni.hideLoading()
			})
		})
		
	}
  },
	methods: {
		// ...mapMutations(['changeUserIdent','changeUserName']),
		toPage(name,params={}){
			this.$navi({
				route:{
					name,
					params
				},
			})
		}
	}
  
}
</script>
